//
// Created by 30986 on 2020/11/21.
//定义一个Employer类 字符数组包含在内 姓名 邮编 地址 性别 电话 
#include <iostream>
#include <cstring>

using namespace std;
class Employer
{
public:
    Employer(char* pname,char* paddr,char* pcity,char* pprov,char* pcode);//函数原型放在类定义中
    void changename(char* pname);
    void display();
    //析构函数
    ~Employer();

protected:     //数据成员设为保护
    char name[20];
    char addr[20];
    char city[20];
    char prov[20];
    char code[20];
};
//函数实现放在类外
Employer::Employer(char* pname,char* paddr,char* pcity,char* pprov,char* pcode)
{
    strncpy(name,pname,sizeof(name));
    name[sizeof(name)-1]='\0';
    strncpy(addr,paddr,sizeof(addr));
    addr[sizeof(addr)-1]='\0';
    strncpy(city,pcity,sizeof(city));
    city[sizeof(city)-1]='\0';
    strncpy(prov,pprov,sizeof(prov));
    prov[sizeof(prov)-1]='\0';
    strncpy(code,pcode,sizeof(code));
    code[sizeof(code)-1]='\0';
    cout<<"构造。。。";
}
Employer::~Employer() {cout<<"析构。。";}
void Employer::display()
{
    cout<<"name:"<<name<<"\n"<<
    "city:"<<city<<endl;
}
void Employer::changename(char *pname) {
    strncpy(name,pname,sizeof(name));
    name[sizeof(name)-1]='\0';
}
int main()
{
    Employer e("a","ab","abc","a","a");
    e.display();
    e.changename("b"); //改名
    e.display();
}